import { GBox } from "../../../../../com/mui/containers/GBox";
import { GBoxDirection } from "../../../../../com/mui/containers/globalVariable/GBoxDirection";
import { RewardItem } from "./RewardItem";
import { UICompomentPool } from "../../../../../com/mui/utils/UICompomentPool";
import { RewardExpLineBox } from "./RewardExpLineBox";
type int = number;
//class RewardGoodBox
    
    export  class RewardGoodBox extends GBox
    {
        constructor(arg1: int=200)
        {
            super();
            this._maxWidth = arg1;
            direction = GBoxDirection.VERTICAL;
            return;
        }

        public set horGap(arg1: int)
        {
            this._horGap = arg1;
            return;
        }

        public addItem(arg1: RewardItem): void
        {
            var loc1=null;
            if (this.lastWidth + arg1.width > this.width) 
            {
                loc1 = UICompomentPool.getUICompoment(RewardExpLineBox);
                loc1.horizontalGap = this._horGap;
                loc1.addChild(arg1);
                addChild(loc1);
            }
            else if (numChildren > 0) 
            {
                loc1 = getChildAt((numChildren - 1)) as RewardExpLineBox;
                loc1.addChild(arg1);
            }
            else 
            {
                loc1 = UICompomentPool.getUICompoment(RewardExpLineBox);
                loc1.horizontalGap = this._horGap;
                loc1.addChild(arg1);
                addChild(loc1);
            }
            if (loc1) 
            {
                loc1.layChildChanged = true;
                loc1.invalidate();
            }
            layChildChanged = true;
            invalidate();
            return;
        }

        public flyItemTo(): void
        {
            var loc1=0;
            var loc3=null;
            var loc2=numChildren;
            while (loc1 < loc2) 
            {
                loc3 = getChildAt(loc1) as RewardExpLineBox;
                loc3.flyItemTo();
                ++loc1;
            }
            return;
        }

        /* internal  */get lastWidth(): int
        {
            var loc2=null;
            var loc3=null;
            var loc4=0;
            var loc5=0;
            var loc1=0;
            if (numChildren > 0) 
            {
                loc2 = getChildAt((numChildren - 1)) as GBox;
                loc5 = loc2.numChildren;
                while (loc4 < loc5) 
                {
                    loc3 = loc2.getChildAt(loc4) as RewardItem;
                    loc1 = loc1 + loc3.width;
                    if (loc4 != (loc5 - 1)) 
                    {
                        loc1 = loc1 + loc2.horizontalGap;
                    }
                    ++loc4;
                }
            }
            return loc1;
        }

        protected /* override */ resetPosition(): void
        {
            var loc1=0;
            var loc2=0;
            var loc4=null;
            loc2 = 0;
            var loc3=this.numChildren;
            if (this.direction != GBoxDirection.VERTICAL) 
            {
                if (this.direction == GBoxDirection.HORIZONTAL) 
                {
                    loc1 = 0;
                    while (loc1 < loc3) 
                    {
                        (loc4 = this.getChildAt(loc1)).x = loc2;
                        if (loc1 != 0) 
                        {
                            loc4.x = loc4.x + horizontalGap;
                        }
                        loc4.y = 0;
                        loc2 = loc4.x + loc4.width;
                        ++loc1;
                    }
                }
            }
            else 
            {
                loc1 = 0;
                while (loc1 < loc3) 
                {
                    (loc4 = this.getChildAt(loc1)).x = 0;
                    loc4.y = loc2;
                    if (loc1 != 0) 
                    {
                        loc4.y = loc4.y + verticalGap;
                    }
                    loc2 = loc4.y + loc4.height;
                    ++loc1;
                }
            }
            return;
        }

        public /* override */ get width(): number
        {
            return this._maxWidth;
        }

        public /* override */ dispose(arg1: Boolean=true): void
        {
            super.dispose(arg1);
            return;
        }

        public /* override */ get height(): number
        {
            return numChildren * 42;
        }

        /* internal */ /* var */_maxWidth: int;

        /* internal */ /* var */_horGap: int;
    }
